
Declare @CECarId bigint
Declare @RefCEUserId bigint

Declare curCarDetail cursor for
Select CECarId, RefCEUserId from tblCarDetail Where RefCEUserId = 138 And CECarId > 1446 And  CECarId < 1469

Open curCarDetail 
		fetch next from curCarDetail into @CECarId, @RefCEUserId
		WHILE (@@fetch_status <> -1)
		BEGIN
			Select @CECarId, @RefCEUserId 
			--Update tblCarPolicy Set IsClaimLastThreeYear = 1 Where CECarId = @CECarId
			
			--INSERT tblCarClaimHistory(CECarId, NOCLast3, NOCLast3Value, NOCLast2, NOCLast2Value, NOCLast1, NOCLast1Value, RefCEUserId)
			--Select @CECarId, 1 as NoCLast3, 1500 as NOCLast3Value, 0 as NoCLast2, 0 as NOCLast2Value, 0 as NoCLast1, 0 as NOCLast1Value, @RefCEUserId
			EXEC sprocProviderCarInsuranceCalculation @CECarId, @RefCEUserId
			fetch next from curCarDetail into @CECarId, @RefCEUserId
		END
Close curCarDetail
Deallocate curCarDetail


SELECT     CMM.Description, CMM.Body, CMM.CC, PC.CompanyName, PCC.ProviderCoverTypeDesc, T.PlanName, T.AnnualPremium, T.Excess, CD.RefCEUserId, T.ModifiedDate 
FROM         tblCarModelInfo AS CMM INNER JOIN
                      tblCarDetail AS CD ON CMM.CarModelId = CD.CarModelId AND CMM.CarMakeId = CD.CarMakeId INNER JOIN
                      tblCarInsuranceTempResult AS T ON CD.CECarId = T.CECarId AND CD.RefCEUserId = T.RefCEUserId INNER JOIN
                      tblProviderCompany AS PC ON T.ProviderCompanyId = PC.ProviderCompanyId INNER JOIN
                      tblProviderCarCoverType AS PCC ON T.ProviderCompanyId = PCC.ProviderCompanyId AND T.CXCoverTypeId = PCC.CXCoverTypeId
WHERE     (T.RefCEUserId = 138) AND (CD.CECarId > 1446) AND (CD.CECarId < 1469)
ORDER BY T.CECarId, T.RefCEUserId, T.CITempResultId, CMM.Description, CMM.Body, CMM.CC

Select Count(CECarId), MAX(CECarId), MIN(CECarId) from tblCarDetail where RefCEUserId = 88
Select Count(CECarId), MAX(CECarId), MIN(CECarId) from tblCarDetail where RefCEUserId = 89
Select Count(CECarId), MAX(CECarId), MIN(CECarId) from tblCarDetail where RefCEUserId = 90
Select Count(CECarId), MAX(CECarId), MIN(CECarId) from tblCarDetail where RefCEUserId = 91
Select Count(CECarId), MAX(CECarId), MIN(CECarId) from tblCarDetail where RefCEUserId = 92

Update tblCarPolicy Set NoOfDriver = 1 Where  RefCEUserId = 138 And CECarId > 1446 And  CECarId < 1469

Update tblCarDetail Set IsPeak = 0 Where  RefCEUserId = 138 And CECarId > 1446 And  CECarId < 1469

select * from tblCarPolicy Where RefCEUserId = 138 And CECarId > 1446 And  CECarId < 1469

Update tblCarPolicy Set NCDPercent = 20 Where  RefCEUserId = 138 And CECarId > 1446 And  CECarId < 1469